package savet.util;

import savet.util.io.ArquivoUtil;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import savet.entidades.Ementa;
import savet.repositorio.EmentaJpaController;

/**
 *
 * @author Adisson Marinho
 */
public class EmentarioToFile {

    public static void main(String[] args) {
//        toFile();
        readFile();
    }

    private static void toFile() {
        try {
            EmentaJpaController controller = new EmentaJpaController();
            List<Ementa> ementas = controller.findEmentaEntities();
            ArquivoUtil.salvarComFileChooser(new LinkedList(ementas));
        } catch (IOException ex) {
            Logger.getLogger(EmentarioToFile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private static void readFile() {
        try {
            List<Ementa> ementas = (List<Ementa>) ArquivoUtil.abrirComFileChooser();
            int contador = 0;
            for (Ementa ementa : ementas) {
                System.out.println(++contador + " - " + ementa);
            }
        } catch (IOException ex) {
            Logger.getLogger(EmentarioToFile.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(EmentarioToFile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
